#include "dialogchoixlot.h"

DialogChoixLot::DialogChoixLot(QWidget *parent) :
    QDialog(parent)
{
    ui.setupUi(this);
}

DialogChoixLot::DialogChoixLot(QWidget *parent, QList<Image> listeImages, typeAppel type) :
    QDialog(parent)
{
    int i;

    ui.setupUi(this);

    this->type = type;

    checkBox = (QCheckBox **)malloc(listeImages.size()*sizeof(QCheckBox *));
    nbImages=listeImages.size();

    for(i=0;i<listeImages.size();i++)
    {
        if(listeImages[i].estGris == false)
        {
            checkBox[i] = new QCheckBox(QString((listeImages[i].getNom()).c_str()));
            ui.vLayConteneur->addWidget(checkBox[i]);
        }
        else
        {
            checkBox[i] = NULL;
        }
    }
    ui.vLayConteneur->addSpacerItem(new QSpacerItem(20,20,QSizePolicy::Minimum,QSizePolicy::Expanding));


    connect(ui.buttonBoxOkAnnuler, SIGNAL(accepted()), this, SLOT(validation()));
}

DialogChoixLot::~DialogChoixLot()
{

}

void DialogChoixLot::validation()
{
    int i;
    bool * checkedIndex = (bool *) malloc(nbImages*sizeof(bool));
    for(i=0;i<nbImages;i++)
    {
        if(checkBox[i] != NULL && checkBox[i]->isChecked())
        {
            checkedIndex[i]=true;
        }
        else
        {
            checkedIndex[i]=false;
        }
    }

    switch(type)
    {
        case calculDELot :
            emit retourDialogCalcDELot(checkedIndex);
            break;
        case categories :
            emit retourDialogCalcCategories(checkedIndex);
            break;
        case creationIndex :
            emit retourCreationIndex(checkedIndex);
            break;
    }

    accept();
}
